/*
 * @Author: 鱿鱼溪学院
 * @Date: 2025-04-14 01:09:08
 * @LastEditTime: 2025-07-28 00:58:18
 * @LastEditors: 鱿鱼溪学院
 * @Description:
 * @FilePath: \yyx-web\src\api\login.ts
 * Copyright 鱿鱼溪学院 by edu v1.0
 * 天道酬勤
 */
import http from '@/utils/http'

//统一接口管理
enum API {
  PHONELOGINWITHOUTCODE_URL = '/aa/user/phoneLoginWithoutVerification'
}

export interface LoginParams {
  phone: string
}

// 实际后端返回的数据结构
interface ApiResponse<T> {
  token: any
  code: number
  data: T
}

// 登录返回的数据类型
interface AuthData {
  token: string
}

export type LoginResponse = ApiResponse<AuthData>

//用户名，密码登录
export function loginByJson(data: LoginParams): Promise<LoginResponse> {
  return http({
    url: 'aa/user/login',
    method: 'post',
    data: data
  })
}

//手机登录接口
export function loginByPhone(data: LoginParams): Promise<LoginResponse> {
  return http({
    url: '/aa/user/loginByPhone',
    method: 'post',
    data: data
  })
}

//手机登录接口(无需验证码)
export function loginByPhoneNoCaptcha(
  data: LoginParams
): Promise<LoginResponse> {
  return http({
    url: API.PHONELOGINWITHOUTCODE_URL,
    method: 'post',
    data: data
  })
}
